package org.jeecg.flowable.controller.definition;


import cn.hutool.db.PageResult;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.flowable.controller.definition.vo.process.BpmProcessDefinitionListReqVO;
import org.jeecg.flowable.controller.definition.vo.process.BpmProcessDefinitionPageItemRespVO;
import org.jeecg.flowable.controller.definition.vo.process.BpmProcessDefinitionPageReqVO;
import org.jeecg.flowable.controller.definition.vo.process.BpmProcessDefinitionRespVO;
import org.jeecg.flowable.service.definition.BpmProcessDefinitionService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/bpm/process-definition")
@Validated
public class BpmProcessDefinitionController {

    @Resource
    private BpmProcessDefinitionService bpmDefinitionService;

    @GetMapping("/page")
    @AutoLog(value = "获得流程定义分页")
    @ApiOperation(value="获得流程定义分页", notes="获得流程定义分页")
    public CommonResult<PageResult<BpmProcessDefinitionPageItemRespVO>> getProcessDefinitionPage(
            BpmProcessDefinitionPageReqVO pageReqVO) {
        return success(bpmDefinitionService.getProcessDefinitionPage(pageReqVO));
    }

    @GetMapping ("/list")
    @AutoLog(value = "获得流程定义列表")
    @ApiOperation(value="获得流程定义列表", notes="获得流程定义列表")
    public Result<?> getProcessDefinitionList(
            BpmProcessDefinitionListReqVO listReqVO) {
        return Result.ok(bpmDefinitionService.getProcessDefinitionList(listReqVO));
    }

    @GetMapping ("/get-bpmn-xml")
    @AutoLog(value = "获得流程定义的 BPMN XML")
    @ApiOperation(value="获得流程定义的 BPMN XML", notes="获得流程定义的 BPMN XML")
    public Result<?> getProcessDefinitionBpmnXML(@RequestParam("id") String id) {
        String bpmnXML = bpmDefinitionService.getProcessDefinitionBpmnXML(id);
        return Result.ok(bpmnXML);
    }
}
